<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition >
        <h:panelGrid columns="2">
            <h:outputText value="Invoice Number: "/>
            <h:outputText value="#{customerInvoiceEntityController.selected.id}" title="#{bundle.ViewCustomerInvoiceEntityTitle_id}"/>

            <h:outputText value="Date of Invoice: "/>
            <h:outputText value="#{customerInvoiceEntityController.selected.createdAt}" title="#{bundle.ViewCustomerInvoiceEntityTitle_createdAt}">
                <f:convertDateTime pattern="MM/dd/yyyy" />
            </h:outputText>

            <h:outputText value="Billing Address: "/>
            <h:outputText value="#{customerInvoiceEntityController.selected.billingRequest.salesOrder.purchaseOrder.billingAddress.address}"/>

            <h:outputText value=" "/>
            <h:outputText value="#{customerInvoiceEntityController.selected.billingRequest.salesOrder.customer.companyName} Finance Department"/>

            <h:outputText value="Total Due: " styleClass="important"/>
            <h:outputText value="#{customerInvoiceEntityController.selected.amount}" styleClass="important"/>

        </h:panelGrid>

        <p:separator />

        <c:forEach items="#{customerInvoiceEntityController.selected.billingRequest.shippingOrders}" var="shippingOrder" >
            <h:panelGrid columns="2">
                <h:outputText value="Shipping Order No: " />
                <h:outputText value="#{shippingOrder.id}" />
                <h:outputText value="Destination: " />
                <h:outputText value="#{shippingOrder.address.address}" />
            </h:panelGrid>

            <h:dataTable value="#{shippingOrder.PQPs}" var="pqp" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Product"/>
                    </f:facet>
                    <h:outputText value="#{pqp.product.productName}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Quantity(case)"/>
                    </f:facet>
                    <h:outputText value="#{pqp.quantity}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Price($)"/>
                    </f:facet>
                    <h:outputText value="#{pqp.price}"/>
                </h:column>
            </h:dataTable>

            <h:panelGrid columns="2">
                <h:outputText value="Sub total($): " styleClass="important"/>
                <h:outputText value="#{shippingOrder.packingOrder.totalPrice}" styleClass="important"/>
            </h:panelGrid>

            <p:separator />
        </c:forEach>

        <h:panelGrid columns="2">
            <h:outputText value="Total($): "/>
            <h:outputText value="#{customerInvoiceEntityController.selected.billingRequest.requestedAmount}" />

            <h:outputText value="Paid with Cash-in-Advance($): " rendered="#{customerInvoiceEntityController.selected.displayCIA}"/>
            <h:outputText value="#{customerInvoiceEntityController.selected.billingRequest.salesOrder.cashPayable}" rendered="#{customerInvoiceEntityController.selected.displayCIA}"/>

            <h:outputText value="Total Due($): " styleClass="important"/>
            <h:outputText value="#{customerInvoiceEntityController.selected.amount}" styleClass="important"/>

            <h:outputText value="Invoice Prepared By: "/>
            <h:outputText value="#{customerInvoiceEntityController.selected.createdBy.fullname}" />
        </h:panelGrid>

        <p:separator rendered="#{customerInvoiceEntityController.selected.discountPenaltyApply()}"/>
        <h:panelGrid columns="1" rendered="#{customerInvoiceEntityController.selected.discountPenaltyApply()}">
            <h:outputText value="Payment is due by #{customerInvoiceEntityController.selected.dueDate}. 
                          A penalty charge of ($) #{customerInvoiceEntityController.selected.latePenalty} is applicable after abovementioned date." >
            </h:outputText>
            <h:outputText value="Payment made by #{customerInvoiceEntityController.selected.discountDueDate} will qualify for a rebate of amount ($) #{customerInvoiceEntityController.selected.earlyRebate}.">
            </h:outputText>
        </h:panelGrid>

        <p:separator />
        <h:outputText value="Bank: OCBC | Account: Kent Ridge Technology Ltd. | Account No: 2349-2382-32"/>

        <p:separator />
        <h:panelGrid columns="1" >
            <h:outputText value="Merlion Food Ltd, 21A Sierra Road, Singapore 719283"/>
            <h:outputText value="Tel: +65 67492700"/>
            <h:outputText value="Email: info@merlionfood.com"/>
        </h:panelGrid>

        <p:separator />
    </ui:composition>

</html>
